package com.game.web.controller.game;

import com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.core.page.TableDataInfo;
import com.game.common.enums.BusinessType;
import com.game.common.utils.poi.ExcelUtil;
import com.game.system.domain.game.AccountTemplate;
import com.game.system.service.IAccountTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 账号模板Controller
 *
 * @author Mr.Liu
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/account/template")
public class AccountTemplateController extends BaseController
{
    @Resource
    private IAccountTemplateService accountTemplateService;

    /**
     * 查询账号模板列表
     */
    @PreAuthorize("@ss.hasPermi('account:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountTemplate accountTemplate)
    {
        startPage();
        List<AccountTemplate> list = accountTemplateService.selectAccountTemplateList(accountTemplate);
        return getDataTable(list);
    }

    /**
     * 导出账号模板列表
     */
    @PreAuthorize("@ss.hasPermi('account:template:export')")
    @Log(title = "账号模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountTemplate accountTemplate)
    {
        List<AccountTemplate> list = accountTemplateService.selectAccountTemplateList(accountTemplate);
        ExcelUtil<AccountTemplate> util = new ExcelUtil<>(AccountTemplate.class);
        util.exportExcel(response, list, "账号模板数据");
    }

    /**
     * 获取账号模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('account:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountTemplateService.selectAccountTemplateById(id));
    }

    /**
     * 新增账号模板
     */
    @PreAuthorize("@ss.hasPermi('account:template:add')")
    @Log(title = "账号模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountTemplate accountTemplate)
    {
        return toAjax(accountTemplateService.insertAccountTemplate(accountTemplate));
    }

    /**
     * 修改账号模板
     */
    @PreAuthorize("@ss.hasPermi('account:template:edit')")
    @Log(title = "账号模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountTemplate accountTemplate)
    {
        return toAjax(accountTemplateService.updateAccountTemplate(accountTemplate));
    }

    /**
     * 删除账号模板
     */
    @PreAuthorize("@ss.hasPermi('account:template:remove')")
    @Log(title = "账号模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accountTemplateService.deleteAccountTemplateByIds(ids));
    }
}
